<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets" template="/home.xhtml">
	<ui:define name="corpo">
		<h:form prependId="false">
			<p:panel header="Administrador" style="background: #dbfbda;font-size:15px;min-height:700px;margin-top:10px;float:left;width:99%">
				<h:panelGroup style="float: left;width:250px;" layout="block">
					    <ui:include src="menu.xhtml" />
				</h:panelGroup>
				
				<h:panelGroup layout="block" style="float:left">
					<p:panel header="Consultas" style="width:100%;" id="pnl_cadastro">
						<h:panelGrid columns="4">
							<h:outputLabel value="Selecione tipo de consulta:" />
							<h:selectOneMenu value="#{manterAdministradorBean.administradorForm.consulta.tipoConsulta}" requiredMessage="Campo obrigatório" id="tipoConsulta" required="true" style="width:130px">
								<f:selectItem itemLabel="" noSelectionOption="true"/>
								<f:selectItems value="#{manterAdministradorBean.administradorForm.tipoConsultas}" var="entity" itemValue="#{entity}" itemLabel="#{entity.tipoConsulta}" />
								<f:converter converterId="convertEntity" />
							</h:selectOneMenu>
													
							<h:outputLabel value="Área médica:" />
							<h:selectOneMenu value="#{manterAdministradorBean.administradorForm.areaMedica}" id="areaMedica" required="#{!empty param['btCadastrar']}" requiredMessage="Campo obrigatório">
								<f:selectItem itemLabel="" noSelectionOption="true"/>
								<f:selectItems value="#{manterAdministradorBean.administradorForm.areasMedicas}" var="entity" itemLabel="#{entity.areaMedica}" itemValue="#{entity}" />
								<p:ajax event="change" listener="#{manterAdministradorBean.administradorForm.obterMedicosPorAreaMedica}" process="@this" update="medicos" />
							</h:selectOneMenu>
							
						    <h:outputText />
							<h:message for="tipoConsulta" style="font-size:10px;color:red" id="msgTipoConsulta" />
							<h:outputText />
							<h:message for="areaMedica" style="font-size:10px;color:red" id="msgAreaMedica" />
							
							<h:outputLabel value="Médico:" />
							<h:selectOneMenu id="medicos" value="#{manterAdministradorBean.administradorForm.consulta.medico}" required="true" requiredMessage="Campo obrigatório" style="width:130px">
								<f:selectItem itemLabel="" noSelectionOption="true"/>
								<f:selectItems value="#{manterAdministradorBean.administradorForm.listMedico}" var="entity" itemValue="#{entity}" itemLabel="#{entity.nome}" />
								<f:converter converterId="convertEntity"/>
							</h:selectOneMenu>
							
							<h:outputLabel value="Data da consulta:" />
							<p:inputMask id="data" mask="99/99/9999 99:99" validator="validaDataExistente" value="#{manterAdministradorBean.administradorForm.consulta.dataConsulta}" required="true" requiredMessage="Campo obrigatório">
								<f:convertDateTime pattern="dd/MM/yyyy HH:mm" locale="pt_BR" timeZone="GMT-3" />
							</p:inputMask>
							
							<h:outputText />
							<h:message for="medicos" style="font-size:10px;color:red" id="msgMedicos" />
							<h:outputText />
							<h:message for="data" style="font-size:10px;color:red" id="msgData" />							
							
						</h:panelGrid>

						<h:panelGroup style="text-align:center" layout="block">
							<p:commandButton id="btCadastrar" value="Cadastrar nova consulta" action="#{manterAdministradorBean.cadastrarConsulta}" update="pnl_cadastro,modal_resposta,panelModal" oncomplete="ativaModal();" />
						</h:panelGroup>
					</p:panel>
					
					<p:outputPanel id="panelModal">
						<script type="text/javascript">
							function ativaModal(){
								if(#{!empty requestScope.cad}){
									cadastro_consulta.show();
								}
								
							}						
							
						</script>
					</p:outputPanel>
				
				</h:panelGroup>
				
			</p:panel>

		</h:form>
		

		<p:dialog header="Aviso" widgetVar="cadastro_consulta" resizable="false" modal="true" width="320" showEffect="clip" hideEffect="fold">
			<h:form prependId="false">
				<h:panelGroup layout="block" style="text-align:center" id="modal_resposta">
					<h:message id="msgConsulta" for="modal_resposta" styleClass="#{requestScope.cad eq 'sucess' ? 'sucesso_consulta' : 'erro_consulta'}" />
					<br /><br />
					<p:commandButton value="#{requestScope.cad eq 'sucess' ? 'OK' : 'Corrigir'}" style="font-weight:bold;font-size:14px" onclick="cadastro_consulta.hide();" />
				</h:panelGroup>
				
			</h:form>
		</p:dialog>

	</ui:define>
</ui:composition>